package com.zatech.cgnci.project.service.impl;

import com.zatech.cgnci.project.dto.MessageSendDTO;
import com.zatech.cgnci.project.service.CgnciMessageSendService;
import com.zatech.cgnci.project.service.CgnciMessageService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collections;

@Service
@RequiredArgsConstructor
public class CgnciMessageSendServiceImpl implements CgnciMessageSendService {

    private final CgnciMessageService messageService;

    @Override
    public void sendPolicyExpireMessage(String policyNo, String receiver) {
        MessageSendDTO sendDTO = new MessageSendDTO();
        sendDTO.setTitle("保单到期提醒");
        sendDTO.setContent("您在保险核心业务系统中创建的保单：" + policyNo + "即将到期，请关注。");
        sendDTO.setMessageType("NOTICE");
        sendDTO.setBusinessType("POLICY_EXPIRE");
        sendDTO.setBusinessNo(policyNo);
        sendDTO.setReceivers(Collections.singletonList(receiver));
        messageService.sendSystemMessage(sendDTO);
    }

    @Override
    public void sendContractExpireMessage(String contractNo, String contractName, String receiver) {
        MessageSendDTO sendDTO = new MessageSendDTO();
        sendDTO.setTitle("合约到期提醒");
        sendDTO.setContent("您在保险核心业务系统中创建的合约：" + contractName + "-" + contractNo + "即将到期，请关注。");
        sendDTO.setMessageType("NOTICE");
        sendDTO.setBusinessType("CONTRACT_EXPIRE");
        sendDTO.setBusinessNo(contractNo);
        sendDTO.setReceivers(Collections.singletonList(receiver));
        messageService.sendSystemMessage(sendDTO);
    }

    @Override
    public void sendBillExpireMessage(String billNo, String receiver) {
        MessageSendDTO sendDTO = new MessageSendDTO();
        sendDTO.setTitle("账单到期提醒");
        sendDTO.setContent("您在保险核心业务系统中创建的账单：" + billNo + "即将到期，请关注。");
        sendDTO.setMessageType("NOTICE");
        sendDTO.setBusinessType("BILL_EXPIRE");
        sendDTO.setBusinessNo(billNo);
        sendDTO.setReceivers(Collections.singletonList(receiver));
        messageService.sendSystemMessage(sendDTO);
    }

    @Override
    public void sendRatingUpdateMessage(String reinsurerName, String receiver) {
        MessageSendDTO sendDTO = new MessageSendDTO();
        sendDTO.setTitle("再保人评级更新提醒");
        sendDTO.setContent("您在保险核心业务系统中管理的再保人：" + reinsurerName + "评级需要更新，请及时进行更新。");
        sendDTO.setMessageType("NOTICE");
        sendDTO.setBusinessType("REINSURER_RATING");
        sendDTO.setReceivers(Collections.singletonList(receiver));
        messageService.sendSystemMessage(sendDTO);
    }

    @Override
    public void sendRatingDowngradeMessage(String reinsurerName, String rating, String receiver) {
        MessageSendDTO sendDTO = new MessageSendDTO();
        sendDTO.setTitle("再保人评级下调提醒");
        sendDTO.setContent("您在保险核心业务系统中管理的再保人：" + reinsurerName + "评级下调至" + rating + "，请关注。");
        sendDTO.setMessageType("NOTICE");
        sendDTO.setBusinessType("RATING_DOWNGRADE");
        sendDTO.setReceivers(Collections.singletonList(receiver));
        messageService.sendSystemMessage(sendDTO);
    }
} 